﻿{extend name="public:base" /}

{block name="content"}

<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-lg-12">
            <div class="ibox ">
                <div class="ibox-content">
                    <form method="post">
                        <div class="box-item">
                            <div class="form-group row"><label class="col-sm-1 col-form-label">封面图</label>
                                <div class="col-sm-6">
                                    <input type="file" id="img_file" accept="image/*" style="display: none">
                                    <input type="hidden" class="hidden_value" name="img" id="img" value="{$info['img']|default=''}"/>
                                    <div class="btn btn-w-m btn-primary" onclick="uploadImage('img_file', 'img', 'form-uploaded-box-single', false, 1)">原图上传</div>
                                    <div class="btn btn-w-m btn-primary" onclick="openCrop('form-uploaded-box-single', 1)">裁剪上传</div>

                                    <div class="form-uploaded-box" id="form-uploaded-box-single" style="width: 140px">
                                        {if $info.img}
                                        <div class="form-uploaded-img-box">
                                            <img class="form-uploaded-box-img" src="{:getPicture($info.img)}" data-id="{$info.img}">
                                            <i class="form-uploaded-img-preview iconfont icon-yulan" onclick="previewImg(this, 'form-uploaded-img-preview')"></i>
                                            <i class="form-uploaded-img-del iconfont icon-close" onclick="delImage(this, 'cropper_uploaded_img_ids', 'cropper_uploaded_img_paths', 'form-')"></i>
                                        </div>
                                        {/if}
                                    </div>
                                </div>

                            </div>
                            <div class="hr-line-dashed"></div>
                        </div>

                        <div class="box-item">
                            <div class="form-group row">
                                <label class="col-sm-1 col-form-label">请选择类型</label>
                                <div class="col-sm-1">
                                    <select class="form-control type_select" name="type">
                                        <option value="1" {$info.type != 1 ? 'selected' : ''}>商品</option>
                                        <option value="2" {$info.type == 2 ? 'selected' : ''}>文章</option>
                                    </select>
                                </div>
                                <div class="col-sm-3">
                                    <select class="form-control to_id_select" name="to_id">
                                        <option value="0">请选择跳转对象</option>
                                        {volist name="goods_list" id="vo"}
                                        <option value="{$vo.id}">{$vo.name}</option>
                                        {/volist}
                                    </select>
                                </div>
                            </div>
                            <div class="hr-line-dashed"></div>
                        </div>

                        <div class="form-group row">
                            <div class="col-sm-4 col-sm-offset-2">
                                <button type="button" class="btn btn-w-m btn-default back-page">返回</button>
                                <button type="button" class="btn btn-w-m btn-primary ajax-post">提交</button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>

{include file="public/cropper-img-mask" cropper_uploaded_img_ids="cropper_uploaded_img_ids" cropper_uploaded_img_paths="cropper_uploaded_img_paths" crop_preview_box="crop-preview-box" /}
{include file="public/preview-img-mask" swiper-id="cropper-preview" /}
{/block}

{block name='js'}
<script>
    var goods_list_obj = {$goods_list_obj};
    var article_list_obj = {$article_list_obj};

    $(function (){
        var type = '{$info.type}';
        var to_id = '{$info.to_id}';

        if(type){
            var option = '<option value="0">请选择跳转对象</option>';

            if (type == 1) {
                goods_list_obj.forEach(function (val) {
                    selected = to_id == val.id ? 'selected' : '';
                    option += '<option value="' + val.id + '" '+ selected +'>' + val.name + '</option>';
                })
            } else {
                article_list_obj.forEach(function (val) {
                    selected = to_id == val.id ? 'selected' : '';
                    option += '<option value="' + val.id + '" ' + selected + '>' + val.name + '</option>';
                })
            }

            $('.to_id_select').html(option);
        }
    })

    $('.type_select').change(function (){
        var type = $(this).val();

        var option = '<option value="0">请选择跳转对象</option>';

        if(type == 1){
            goods_list_obj.forEach(function (val){
                option += '<option value="'+ val.id +'">'+ val.name +'</option>';
            })
        }else{
            article_list_obj.forEach(function (val) {
                option += '<option value="' + val.id + '">' + val.name + '</option>';
            })
        }

        $('.to_id_select').html(option);
    })
</script>
{/block}
